package util;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class HashFunc {

	// Use the hashcode of the original string, and take n-bits from the rights
	public static int hashKey(String corpus, int bits) {
		int hashStr = corpus.hashCode();
		int bitmask ;
		if (bits < 32) {
			bitmask = (1 << bits) - 1;
		} else {
			bitmask = 0xFFFFFFFF;
		}
        return hashStr & bitmask;
	}
	
	public static Set<String> hashSet(Map<Object, Double> featureMap, int hashBits) {
		HashSet<String> resultSet = new HashSet<String>();
		for (Map.Entry<Object, Double> me : featureMap.entrySet()) {
			resultSet.add(Integer.toString(hashKey((String)me.getKey(), hashBits)));
		}
		return resultSet;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
